package cn.panda.edu.controller;

import cn.panda.edu.model.Student;
import cn.panda.edu.model.Transaction;
import cn.panda.edu.service.StudentService;
import cn.panda.edu.service.TransactionService;
import cn.panda.edu.util.Constant;
import cn.panda.edu.util.ResultDataUtil;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping(value="/api/admin")
@Api(description="审核")
public class ManageTransactionController {

	@Autowired
	private TransactionService transactionService;
	
	@Autowired
	private StudentService studentService;
	
	/**
	* @Title: QueryStudentFy 
	* @Description: TODO(学生异动 分页) 
	* @param pageIndex
	* @return
	* Map<String,Object>
	 */
	@ApiOperation(value="学生异动 分页")
	@ApiImplicitParams({
		@ApiImplicitParam(name="pageIndex", value="当前页码", required=true, dataType="int", paramType="form"),
		@ApiImplicitParam(name="studentId", value="学生ID", required=false, dataType="int", paramType="form")})
	@RequestMapping(value="queryStudentFy",method=RequestMethod.POST)
	public Map<String, Object> QueryStudentFy(@RequestParam(required=true)Integer pageIndex,Integer studentId){
		System.out.println(pageIndex);
		PageInfo<Transaction> pageInfo = transactionService.selectByPageAndSelective(pageIndex, Constant.PAGE_SIZE, studentId);
		return ResultDataUtil.resData(200, "", pageInfo);
	}
	
	/**
	* @Title: QueryStudentUp 
	* @Description: TODO(学生异动申请 审核 修改状态) 
	* @param transaction
	* @return
	* Map<String,Object>
	 */
	@ApiOperation(value="学生异动申请 审核 修改状态 ")
	@ApiImplicitParam(name="transaction",value="审核类",required=false,dataType="Transaction",paramType="form")
	@RequestMapping(value="QueryStudentUp",method=RequestMethod.POST)
	public Map<String, Object> QueryStudentUp(Transaction transaction ){
		Map<String, Object> map = new HashMap<>();
		int result = transactionService.updateByPrimaryKeySelective(transaction);
		if (result > 0) {
			map = ResultDataUtil.resData(200, "修改成功",null) ;
		}else {
			map = ResultDataUtil.resData(500, "修改失败",null) ;
		}
		return map;
	}
	
	/**
	* @Title: queryStudentMessage 
	* @Description: TODO(学生异动  详情 ) 
	* @param transactionId
	* @param studentId
	* @return
	* Map<String,Object>
	 */
	@ApiOperation(value="学生异动  详情 ")
	@ApiImplicitParams({@ApiImplicitParam(name="transactionId",value="审核ID",required=false,dataType="int",paramType="form"),
						@ApiImplicitParam(name="studentId",value="学生ID",required=false,dataType="int",paramType="form")})
	@RequestMapping(value="queryStudentMessage",method=RequestMethod.POST)
	public Map<String, Object> queryStudentMessage(Integer transactionId, Integer studentId){
		Map<String, Object> map = new HashMap<>();
		Transaction transaction = transactionService.selectByPrimaryKey(transactionId);
		//map.put("transaction", transaction);
//		Student student = studentService.selectByPrimaryKey(studentId);
//		map.put("student", student);
		return ResultDataUtil.resData(200, "", transaction);				
	}
	
	/**
	* @Title: queryMoney 
	* @Description: TODO(学生缴费  审核 详情 ) 
	* @param studentId
	* @param studentName
	* @param pageIndex
	* @return
	* Map<String,Object>
	 */
	@ApiOperation(value="学生缴费  审核 ")
	@ApiImplicitParams({
		@ApiImplicitParam(name = "studentId", value = "学生ID", required =false , dataType = "String"),
		@ApiImplicitParam(name = "pageIndex", value ="当前页码", required =true, dataType = "int")
	})
	@RequestMapping(value="queryMoney",method=RequestMethod.POST)
	public Object queryMoney(String studentId,  Integer pageIndex){
		System.out.println(studentId+"----"+pageIndex);
		Student student = new Student();
		if (studentId != null && !"".equals(studentId)) {
			student.setStudentId(Integer.parseInt(studentId));
		}
		PageInfo<Student> pageInfo = studentService.selectByPageAndSelective(student, pageIndex, Constant.PAGE_SIZE);
		return ResultDataUtil.resData(200, "", pageInfo);				
	}
	
}
